<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let LongestSubstring = function (s) {
        let news = [...s]
        let arr = []
        let newarr = []
        let i = 0
        for (let j = 0; j < s.length; j++) {
          let res = arr.indexOf(news[j])
          // console.log(res);
          if (res === -1) {
            arr.push(news[j])
            // console.log(news[j]);
            // console.log(arr);
            // console.log(arr.length)
            newarr.push(arr.length)
          } else {
            //   // console.log(i);
            arr = []
            // console.log(j)
            // console.log(j-i);
            // console.log(j);
            i = j
            j = j - 1
          }
        }
        // console.log(newarr)
        let max = Math.max.apply(null, newarr)
        console.log(max)
      }
      LongestSubstring('fabcabcdejg')
      LongestSubstring('mmm')
      LongestSubstring('abcdefghij')
    </script>
  </body>
</html>
